<template>
	<view>


		<view class="">

			<view class="banmi_flex a-c p-20">
				<view class="banmi_input_name">短信图形验证码是否开启:</view>
				<view class="m-l-10" @click="on_switch(find.sms_img_code,'sms_img_code')">
					<banmi-switch :is_state="Number(find.sms_img_code)" :is_type="0"></banmi-switch>
				</view>
			</view>
			<view class="banmi_flex a-c p-20 bb">
				<view class="banmi_input_name">短信模式:

				</view>

				<view class=" ">
					<view class="banmi_flex" style="justify-content: flex-start;flex-wrap: wrap;">
						<button style="flex-shrink:0;" class="banmi_flex a-c m-l-10" @click="on_test(index)"
							v-for="(vo,index) in sms_test_list">
							<view class="q-y  banmi_flex a-c j-c"
								:class="find.ip_sms_test == vo.type ? 'key_xz' : 'key_wxz'">
								<text v-if="find.ip_sms_test== vo.type " class="f-14">✓</text>
							</view>
							<text class="f-14 c_7" style="margin-left: 5px;"
								:class="find.ip_sms_test== vo.type ? 'key_color' : ''">{{vo.name}}</text>
						</button>
					</view>
					<view class="" style="margin-left: 10px;padding-top: 5px;">
						<text style="font-size: 14px;color: red;">调试模式不发送验证码，验证码为固定123456</text>
					</view>
				</view>
			</view>

			<view class="banmi_flex a-c p-20 bb">
				<view class="banmi_input_name">短信选择:</view>
				<view class=" ">
					<view class="banmi_flex" style="justify-content: flex-start;flex-wrap: wrap;">
						<button style="flex-shrink:0;" class="banmi_flex a-c m-l-10" @click="on_sms(index)"
							v-for="(vo,index) in sms_list">
							<view class="q-y  banmi_flex a-c j-c" :class="find.sms == vo.type ? 'key_xz' : 'key_wxz'">
								<text v-if="find.sms== vo.type " class="f-14">✓</text>
							</view>
							<text class="f-14 c_7" style="margin-left: 5px;"
								:class="find.sms== vo.type ? 'key_color' : ''">{{vo.name}}</text>
						</button>

					</view>

				</view>
			</view>
			<view class="banmi_flex a-c p-20 bb" style="margin-top: -80rpx;">
				<view class="banmi_input_name"> </view>
				<view class=" ">

					<view style="margin-left: 10px;padding-top: 5px;line-height: 30px;">
						<view class="c-7 f-14">{{find.sms==0? '短信宝': find.sms==1? '阿里云':find.sms==2? '腾讯云': '' }}官网:
							<text class="cred f-14">{{sms_url}}</text>
						</view>
						<view class="c-7" style="font-size: 14px;">设置模板: <text class="cred">{{sms_text}}</text>
						</view>
					</view>
				</view>
			</view>
			<template v-if="find.sms==1">
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">阿里云KeyId:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.ali_accessKeyId" placeholder="请输入accessKeyId">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">阿里云KeySecret:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.ali_accessKeySecret" placeholder="请输入KeySecret">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">签名名称:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.ali_signname" placeholder="签名名称">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">短信模板CODE:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.ali_templateCode" placeholder="短信模板CODE">
						</uni-easyinput>
					</view>
				</view>



			</template>
			<template v-if="find.sms==2">
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">腾讯云secretId:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.tx_secretId" placeholder="请输入secretId">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">腾讯云secretKey:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.tx_secretKey" placeholder="请输入secretKey">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">应用列表AppID:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.tx_smsSdkAppId" placeholder="示例:1400559123">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">短信站点名称:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.tx_signName" placeholder="示例:半米科技">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">短信短信模板id:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.tx_templateId" placeholder="示例:1073405">
						</uni-easyinput>
					</view>
				</view>
			</template>
			<template v-if="find.sms==0">
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">短信宝账号:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.smsbao_name" placeholder="请输入短信宝账号">
						</uni-easyinput>
					</view>
				</view>
				<view class="banmi_flex a-c p-20">
					<view class="banmi_input_name">短信宝密码:</view>
					<view class="banmi_input_view">
						<uni-easyinput v-model="find.smsbao_pwa" placeholder="请输入短信宝密码">
						</uni-easyinput>
					</view>
				</view>
			</template>



			<view class="banmi_flex a-c p-20">
				<view class="banmi_input_name">24小时同一ip最多发送:</view>
				<view class="banmi_input_view">
					<uni-easyinput v-model="find.ip_sms_num" placeholder="条数">
					</uni-easyinput>
				</view>
			</view>
			<view class="banmi_flex a-c p-20">
				<view class="banmi_input_name">24小时同一手机最多发送:</view>
				<view class="banmi_input_view">
					<uni-easyinput v-model="find.tel_sms_num" placeholder="条数">
					</uni-easyinput>
				</view>
			</view>

			<view class="banmi_flex a-c p-20">
				<view class="banmi_input_name"></view>
				<view class="banmi_input_view">
					<button style="background-color: #007AFF;" type="primary" size="mini" @click="on_save"
						class="banmi_but">
						保存
					</button>
				</view>
			</view>



		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-beizhu cancelText="取消" confirmText="确认" lei="0" :name="name" :keya="key" @confirm="ajax_set">
			</uni-popup-beizhu>
		</uni-popup>

	</view>
</template>

<script>
	export default {
		props: {

		},
		data() {
			return {
				find: {
					tx_templateId: '',
					tx_signName: '',
					tx_smsSdkAppId: ''
				},
				sms_text: '',
				name: '',
				key: '',
				sms_test_list: [{
						"type": 0,
						"name": "调试模式",
						"text": ''
					},
					{
						"type": 1,
						"name": "运营模式",
						"text": ''
					},
				],
				sms_list: [{
						"type": 0,
						"name": "短信宝",
						"text": '您的手机验证码为{$code}，在{$time}分钟内有效！',
						'url': 'https://www.smsbao.com/'
					},
					{
						"type": 1,
						"name": "阿里云",
						"text": '您的手机验证码为${code}，在2分钟内有效！',
						'url': 'https://www.aliyun.com/'
					},
					{
						"type": 2,
						"name": "腾讯云",
						"text": '您的手机验证码为{1}，在{2}分钟内有效！',
						'url': 'https://cloud.tencent.com/'
					}
				],
				sms_url: '',
			};
		},
		mounted() {
			this.init();
		},
		methods: {
			async on_save() {
				var that = this;

				const ret = await this.Banmikeji.Settings_set_oss_save(that.find);
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})

			},
			on_test(val) {
				this.find.ip_sms_test = val
			},
			on_sms(val) {
				this.find.sms = val
				this.sms_url = this.sms_list[val]['url']
				this.sms_text = this.sms_list[val]['text']
			},
			change(index) {
				return index ^ 1;
			},
			on_switch(index, name) {
				var that = this;
				index = this.change(index)
				that.key = name;
				that.ajax_set(index);
			},
			async ajax_set(val) {
				var that = this;
				that.requestParams = {};
				that.requestParams[that.key] = val
				that.requestParams['key'] = that.key

				const ret = await this.Banmikeji.Settings_set_key_sets(that.requestParams);
				this.$refs.alertDialog.close()
				if (ret.status != 200) {
					return
				}
				this.find[that.key] = val;



			},
			on_set_name(name, key) {
				this.name = name;
				this.key = key;
				this.$refs.alertDialog.open()
			},
			async init() {
				const ret = await this.Banmikeji.index_index({});
				this.find = ret.data
				this.on_sms(this.find.sms);
			}
		}
	}
</script>

<style lang="scss">
	button {
		padding: 0;
		background: transparent;
	}

	button::after {
		border: none;
	}
</style>